package com.yun.utils;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class ConnectionUtil {

    private static ConnectionFactory connection;

    static {
        connection = new ConnectionFactory();
        connection.setHost("localhost");
        connection.setPort(5672);
        connection.setVirtualHost("/ems");
        connection.setUsername("ems");
        connection.setPassword("123");
    }

    public static Connection getConnection() {
        try {
            return connection.newConnection();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void close(Connection con, Channel channel) {
        try {
            if (channel != null) channel.close();
            if (con != null) con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
